"""
This code is currently broken

small changes are required to adapt it to the new pulsed measurements (without hardware API).

See rabi.py as example.
"""

class Hahn( Rabi ):
    
    """Defines a Hahn-Echo measurement."""

    t_pi2       = Range(low=1., high=100000.,   value=1000.,    desc='pi/2 pulse length',   label='pi/2 [ns]',    mode='text', auto_set=False, enter_set=True)
    t_pi        = Range(low=1., high=100000.,   value=1000.,    desc='pi pulse length',     label='pi [ns]',      mode='text', auto_set=False, enter_set=True)

    def generate_sequence(self):
        tau = self.tau
        laser = self.laser
        wait  = self.wait
        t_pi2  = self.t_pi2
        t_pi   = self.t_pi
        sequence = []
        for t in tau:
            sequence += [  (['mw'],t_pi2), ([],0.5*t), (['mw'],t_pi), ([],0.5*t), (['mw'],t_pi2), (['detect','aom'],laser), ([],wait)  ]
        sequence += [  (['sequence'],100)  ]
        return sequence

    get_set_items = Rabi.get_set_items + ['t_pi2','t_pi']

    traits_view = View(VGroup(HGroup(Item('submit_button',   show_label=False),
                                     Item('remove_button',   show_label=False),
                                     Item('resubmit_button', show_label=False),
                                     Item('priority'),
                                     Item('state', style='readonly'),
                                     Item('run_time', style='readonly',format_str='%.f'),
                                     Item('stop_time'),                                     
                                     ),
                              Tabbed(VGroup(HGroup(Item('frequency',     width=-80, enabled_when='state != "run"'),
                                                   Item('power',         width=-80, enabled_when='state != "run"'),
                                                   Item('t_pi2',         width=-80, enabled_when='state != "run"'),
                                                   Item('t_pi',          width=-80, enabled_when='state != "run"'),),
                                            HGroup(Item('tau_begin',     width=-80, enabled_when='state != "run"'),
                                                   Item('tau_end',       width=-80, enabled_when='state != "run"'),
                                                   Item('tau_delta',     width=-80, enabled_when='state != "run"'),
                                                   ),
                                            label='parameter'
                                            ),
                                     VGroup(HGroup(Item('laser',         width=-80, enabled_when='state != "run"'),
                                                   Item('wait',          width=-80, enabled_when='state != "run"'),
                                                   Item('record_length', width=-80, enabled_when='state != "run"'),
                                                   Item('bin_width',     width=-80, enabled_when='state != "run"'),),
                                            label='settings'
                                            ),
                                     ),
                              ),
                       title='Hahn-Echo Measurement',
                       )
    

class Hahn3pi2( Rabi ):
    
    """Defines a Hahn-Echo measurement with both pi/2 and 3pi/2 readout pulse."""

    t_pi2       = Range(low=1., high=100000.,   value=1000.,    desc='pi/2 pulse length',   label='pi/2 [ns]',    mode='text', auto_set=False, enter_set=True)
    t_pi        = Range(low=1., high=100000.,   value=1000.,    desc='pi pulse length',     label='pi [ns]',      mode='text', auto_set=False, enter_set=True)
    t_3pi2      = Range(low=1., high=100000.,   value=1000.,    desc='3pi/2 pulse length',  label='3pi/2 [ns]',   mode='text', auto_set=False, enter_set=True)

    def generate_sequence(self):
        tau = self.tau
        laser = self.laser
        wait  = self.wait
        t_pi2  = self.t_pi2
        t_pi   = self.t_pi
        t_3pi2 = self.t_3pi2
        sequence = []
        for t in tau:
            sequence += [  (['mw'],t_pi2), ([],0.5*t), (['mw'],t_pi), ([],0.5*t), (['mw'],t_pi2), (['detect','aom'],laser), ([],wait)  ]
        for t in tau:
            sequence += [  (['mw'],t_pi2), ([],0.5*t), (['mw'],t_pi), ([],0.5*t), (['mw'],t_3pi2), (['detect','aom'],laser), ([],wait)  ]
        sequence += [  (['sequence'],100)  ]
        return sequence

    traits_view = View(VGroup(HGroup(Item('submit_button',   show_label=False),
                                     Item('remove_button',   show_label=False),
                                     Item('resubmit_button', show_label=False),
                                     Item('priority'),
                                     Item('state', style='readonly'),
                                     Item('run_time', style='readonly',format_str='%.f'),
                                     Item('stop_time'),
                                     ),
                              Tabbed(VGroup(HGroup(Item('frequency',     width=-80, enabled_when='state != "run"'),
                                                   Item('power',         width=-80, enabled_when='state != "run"'),
                                                   Item('t_pi2',         width=-80, enabled_when='state != "run"'),
                                                   Item('t_pi',          width=-80, enabled_when='state != "run"'),
                                                   Item('t_3pi2',        width=-80, enabled_when='state != "run"'),),
                                            HGroup(Item('tau_begin',     width=-80, enabled_when='state != "run"'),
                                                   Item('tau_end',       width=-80, enabled_when='state != "run"'),
                                                   Item('tau_delta',     width=-80, enabled_when='state != "run"'),
                                                   ),
                                            label='parameter'
                                            ),
                                     VGroup(HGroup(Item('laser',         width=-80, enabled_when='state != "run"'),
                                                   Item('wait',          width=-80, enabled_when='state != "run"'),
                                                   Item('record_length', width=-80, enabled_when='state != "run"'),
                                                   Item('bin_width',     width=-80, enabled_when='state != "run"'),),
                                            label='settings'
                                            ),
                                     ),
                              ),
                       title='Hahn-Echo Measurement with both pi/2 and 3pi/2 readout pulse',
                       )
    
    get_set_items = Rabi.get_set_items + ['t_pi2','t_pi','t_3pi2']
